import 'package:json_annotation/json_annotation.dart';

part 'state_response.g.dart';

/// 交易状态响应实体
@JsonSerializable()
class StateResponse extends Object {
  /// 交易创建时间（ISO8601格式）
  @JsonKey(name: 'created', defaultValue: '')
  String created;

  /// 是否可重复执行该交易
  @JsonKey(name: 'isRepeatable', defaultValue: false)
  bool isRepeatable;

  /// 交易结果状态码
  @JsonKey(name: 'resultCode', defaultValue: 0)
  int resultCode;

  /// 交易状态值：
  /// TransactionState
  @JsonKey(name: 'state', defaultValue: 8)
  int state;

  /// 交易唯一标识符
  @JsonKey(name: 'transactionId', defaultValue: '')
  String transactionId;

  /// 最后更新时间（ISO8601格式）
  @JsonKey(name: 'updated', defaultValue: '')
  String updated;

  StateResponse(
    this.created,
    this.isRepeatable,
    this.resultCode,
    this.state,
    this.transactionId,
    this.updated,
  );

  /// 从JSON字典构造对象
  factory StateResponse.fromJson(Map<String, dynamic> srcJson) =>
      _$StateResponseFromJson(srcJson);

  /// 将对象转为JSON字典
  Map<String, dynamic> toJson() => _$StateResponseToJson(this);
}
